package com.zpf.controller;

import cn.dsna.util.images.ValidateCode;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//生成消费者登录页面的验证码
@WebServlet("/code")
public class CodeController extends BaseServlet {
    public void createCode(HttpServletRequest request, HttpServletResponse response) throws Exception{
        //1.创建验证码工具类, 宽，高，个数，长度
        ValidateCode validateCode = new ValidateCode(100, 30, 4,10);
        //2.获取验证码字符内容
        String code = validateCode.getCode();
        //3.将验证码字符串内容保存到tomcat的session会话对象中，供校验的时候使用
        request.getSession().setAttribute("code",code);
        //4.将验证码图片通过流写回到页面展示
        validateCode.write(response.getOutputStream());
    }
}
